package com.hospital;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hospital.pony.base.BaseActivity;
import com.hospital.pony.config.Consts;
import com.hospital.pony.model.ApplyModel;
import com.hospital.pony.model.ResponseEntry;
import com.hospital.pony.util.ToastUtil;

import net.tsz.afinal.http.AjaxParams;

public class CreateNoticeActivity extends BaseActivity {

	// title
	private TextView mTvTitle;
	// 返回
	private ImageView mIvBack;
	// 查询按钮
	private Button mbtnAdd;

	private TextView personName;
	private EditText shopMessage;



	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_create_notice);
		initWidget();
		initData();
	}

	@Override
	public void initWidget() {

		personName = (TextView) findViewById(R.id.personName);
		shopMessage = (EditText) findViewById(R.id.shopMessage);


		mbtnAdd = (Button) findViewById(R.id.mbtnAdd);
		mIvBack = (ImageView) findViewById(R.id.mIvBack);
		mTvTitle = (TextView) findViewById(R.id.mTvTitle);
		mTvTitle.setText("添加病历信息");
		mIvBack.setVisibility(View.VISIBLE);
		mIvBack.setOnClickListener(this);
		mbtnAdd.setOnClickListener(this);


		shopMessage.setText("没有在医疗机构建立门（急）诊病历档案的，患者就诊的门（急）诊病历等由患者自行保管，患者有责任妥善保存，使其保持原貌及完整性，不得在病历上涂改、添加等。如果患者丢失自行保管的病历资料");

	}


	@Override
	public void onClick(View v) {

		if(v.getId()==R.id.mIvBack){
			CreateNoticeActivity.this.finish();
		}if(v.getId()==R.id.mbtnAdd){
			updateMoneyLine(false);
		}
	}

	private int posIndex = 0;

	ApplyModel applyModel;
	@Override
	public void initData() {
		applyModel = (ApplyModel) this.getIntent().getSerializableExtra("msg");
		personName.setText(applyModel.getApplyUserName());
	}

	private void updateMoneyLine(boolean isShow) {
		AjaxParams params = new AjaxParams();
		params.put("action_flag", "updateBingLi");
		params.put("applyNotice", shopMessage.getText().toString());
		params.put("applyId", applyModel.getApplyId());
		httpPost(Consts.URL + Consts.APP.HospitalAction, params, Consts.actionId.resultCode, isShow, "正在注册...");
	}

	@Override
	protected void callBackSuccess(ResponseEntry entry, int actionId) {
		super.callBackSuccess(entry, actionId);
		switch (actionId) {
		case Consts.actionId.resultCode:
			ToastUtil.show(this, entry.getRepMsg());
			new Handler().postDelayed(new Runnable() {
				@Override
				public void run() {
					finish();
				}
			}, 2000);
			break;
		}
	}

}
